/*
 * ServerSocket.h
 *
 *  Created on: Dec 19, 2013
 *      Author: vipatil
 */

#ifndef SERVERSOCKET_H_
#define SERVERSOCKET_H_

//
#include "ThreadPool.h"

#include <memory>
#include <vector>
#include <atomic>
#include <mutex>

namespace ServerThread
{

typedef std::unique_ptr<std::thread> ClientPtr;
typedef std::unique_ptr<ThreadPool::ThreadPool> ThreadPoolPtr;

class ServerThread
{
private:

  std::atomic<bool>      _timeToExit;
  std::string            _threadID;
  int                    _serverFD;
  ThreadPoolPtr          _ThreadPool;

  std::mutex             _counterMutex;
  unsigned long          _msgCount;

  void handleThread(int clientFD);

  void setupThread();

  void handleShutdown();



public:
  ServerThread();
  virtual ~ServerThread();

  void operator()();

  void setExitFlag();
  bool exit();

  void msgStatus(int msgCount);

  unsigned long msgCount();
};





}

#endif /* SERVERSOCKET_H_ */
